<template>
	<view class="container">
		<view v-for="(item,index) in tableData">
			<uni-card :title="item.xm" :sub-title="'医疗组:'+item.hzdeptname" :extra="'编号：'+item.bh" :thumbnail="avatar" @click="onClick">
				<text class="uni-body">伤部:{{item.sb==null?'':item.sb.join(',')}}</text>
				<text class="uni-body">伤类:{{item.sl==null?'':item.sl.join(',')}}</text>
				<text class="uni-body">伤型:{{item.sx==null?'':item.sx.join(',')}}</text>
				<text class="uni-body">并发症:{{item.bfz==null?'':item.bfz.join(',')}}</text>
				<text class="uni-body">伤势:{{item.ss}}</text>
				<text class="uni-body">伤票类型:{{item.splx}}</text>
				<button style="color: #fff; background-color: #2e5c8a; margin-left: 10%;" size="mini" @click="circulation(item)">流转</button>
				<!-- <button style="color: #fff; background-color: #474700; margin-left: 10%;" size="mini" @click="orders(item)">医嘱</button> -->
				<button style="color: #fff; background-color: #2e5c8a; margin-left: 10%;" size="mini" @click="nursing(item)">护理</button>
				<button style="color: #fff; background-color: #2e5c8a; margin-left: 10%;" size="mini" @click="illness(item)">病情</button>
				<button style="color: #fff; background-color: #2e5c8a; margin-left: 10%;" size="mini" @click="evacuation(item)">后送</button>
			</uni-card>
		</view>
		<uni-load-more status="no-more" :contentText="contentText" />
		<!-- 流转弹窗 -->
		<uni-popup ref="popup" background-color="#fff" >
			<view class="popup-content" :class="{ 'popup-height': type ===  'left' || type === 'right' }">
				<uni-section title="流转" type="line">
					<view class="example">
						<!-- 基础用法，不包含校验规则 -->
						<uni-forms ref="baseForm" :modelValue="baseFormData" label-width="100px">
							<uni-data-select v-model="baseFormData.office" :localdata="typeArrOffice"
								placeholder="请选择伤员分组" />
							<uni-easyinput type="textarea" v-model="baseFormData.name" placeholder="请输入初步诊断" />
						</uni-forms>
					</view>
					<view class="fixedBottom">
						<button class="trueDecide" @click="trueDecide()">确定</button>
						<button class="cancel" @click="cancel()">取消</button>
					</view>
				</uni-section>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		viewWounded,
		grouping,
		Circulation,
		removeById,
		upload
	} from '../../api/huanzhe.js'
	import {
		toast,
		signOut,
		getStorageSync,
		useRouter,
		removeStorageSync
	} from '../../utils/utils.js'
	export default {
		data() {
			return {
				status: 'more',
				Circulation:{
					hzId:null,
					bz:null,
					deptId:null,
					deptname:null
				},
				typeArrOffice: [],
				baseFormData:[],
				tableData:[],
				InquireData:{
					pageNum: 1,
					skipCount: 0,
					pageSize: 20,
					bz: 1
				}
			}
		},
		onLoad(){
			this.uploaded()
			this.groupingQuery()
		},
		// 触底加载
		
		onReachBottom(e) {
				this.InquireData.pageNum++;
				this.uploaded()
		},
		methods:{
			// 后送
			evacuation(item){
				const {
					id,
					xm,
					xb,
					nl
				} = item
				useRouter('/pages/evacuation/newEvacuationv4', {
					id,
					xm,
					xb,
					nl
				}, 'navigateTo')
			},
			// 医嘱
			orders(item){
				console.log(item);
				useRouter('/pages/casualtyList/newOrdersv4?bh='+item.bh+'&xm='+item.xm+'&xb='+item.xb+'&nl='+item.nl+'&id='+item.id)
			},
			// 护理
			nursing(item){
				useRouter('/pages/nursing/newNursingv4',{
					hzId:item.id,
					xm:item.xm,
					xb:item.xb,
					nl:item.nl
				},'navigateTo')
			},
			// 流转弹窗取消
			cancel() {
				this.$refs.popup.close()
			},
			// 查询分组
			groupingQuery(){
				grouping().then(res=>{
					res.data.forEach((item, index) => {
						var typeArrOffice = {
							value: item.dictLabel,
							text: item.dictValue
						}
						this.typeArrOffice.push(typeArrOffice)
					})
					this.typeArrOffice.splice(3,1)
				})
			},
			// 病情
			illness(item){
				const {
					id,
					xm,
					xb,
					nl
				}=item
				useRouter('/pages/illness/newIllnessv4', {
					id,
					xm,
					xb,
					nl
				}, 'navigateTo')
			},
			// 流转弹窗成功
			trueDecide() {
				this.Circulation.bz=this.baseFormData.name
				this.Circulation.deptId=this.baseFormData.office
				this.typeArrOffice.forEach((item,index)=>{
					if(this.baseFormData.office==item.value){
						this.Circulation.deptname=item.text
					}
				})
				Circulation(this.Circulation).then(res=>{
					if(res.code==200){
						toast("流转成功")
					}else{
						toast("流转失败")
					}
					this.Circulation={}
				})
				this.$refs.popup.close()
				this.$refs.more.close()
			},
			// 流转
			circulation(item){
				this.Circulation.hzId=item.id
				this.$refs.popup.open("bottom")
			},
			// 查看
			uploaded() {
				viewWounded(this.InquireData).then(res => {
					console.log(res);
					if (res.code == 200) {
						this.status = this.InquireData.pageNum >= Math.ceil(res.total / 10) ? 'no-more' : 'more'
						uni.stopPullDownRefresh();
				
						if (this.InquireData.pageNum > 1) {
							this.tableData.push(...res.rows)
				
						} else {
							console.log(res.rows);
							this.tableData = res.rows
						}
					}
				})
			}
		}
	}
</script>

<style>
	.uni-group {
		display: flex;
		align-items: center;
	}
	.uni-body{
		display:block
	}
</style>